<?php echo $this->doctype(); ?>
<html>
<head>
	<?php echo $this->headLink()->appendStylesheet('/Apprentice_CMS/public/css/StyleSheet.css'); ?>
	<?php echo $this->headLink()->appendStylesheet('/Apprentice_CMS/public/css/editor.css'); ?>
	<?php echo $this->headScript()->appendFile('/Apprentice_CMS/public/js/editor.js'); ?>
	<?php echo $this->headScript()->appendFile('/Apprentice_CMS/public/js/jquery-1.6.2.min.js'); ?>
	<?php echo $this->headScript()->appendFile('/Apprentice_CMS/public/js/jquery-ui-1.8.16.custom.min.js'); ?>
	<?php echo $this->headScript()->appendFile('/Apprentice_CMS/public/js/jquery.confirm-1.3.js'); ?>
    <link type="text/css" rel="Stylesheet" href="StyleSheet.css" />
	<script>
	$("document").ready(function(){
		var main=$('#main');
        var idname="block";
        var idnum=1;
		var i=0;
		$(".Newblock").click(ggg);
		/*
        $(".Newblock").bind("click",function(){
            var tmp=$(this).parent();
            var temp=$("<div></div>");
        	var newdiv=$("<div></div>").attr("class","block").attr("id",idname+idnum ).insertAfter(tmp);
            var newtitle=$("<h3>Block content</h3>");
            var newcontrol=$("<div class='control'><img src='/Apprentice_CMS/public/images/icon/Delete.png' title='Delete block' class='imgDelete'/></div>");
            var newclear= $("<div class='clear'></div>");
            var newcontent=$("<div class='content'>my content</div>");
            //var newpanel=$("<div class='panel' ><img src='/Apprentice_CMS/public/images/icon/New-document.png' class='Newblock' /><img src='/Apprentice_CMS/public/images/icon/New-image.png' /> <img src='/Apprentice_CMS/public/images/icon/New-table.png' /> </div>").insertAfter(newdiv);
			var newpanel=$("<div class='panel' ><img src='/Apprentice_CMS/public/images/icon/New-document.png' class='Newblock' id='"+i+"'/><img src='/Apprentice_CMS/public/images/icon/New-image.png' /> <img src='/Apprentice_CMS/public/images/icon/New-table.png' /> </div>").insertAfter(newdiv);
        	$("#"+i).click(ggg);
            newtitle.appendTo(newdiv);
            newcontent.appendTo(newdiv);
            newcontrol.appendTo(newdiv);
            newclear.appendTo(newdiv);
            //newpanel.appendTo(newdiv);
            
            i+=1;
            $(".content").bind("dblclick",function(){
            	var temp=$(this);
                $("#dialog-form").dialog({
            		autoOpen: false,
            		height: 400,
            		width: 800,
            		modal: true,
            		buttons:{
            			"Save":function(){
            				//temp.html($("#texta").val());
            				$(this).dialog("close");
            				}
            			},
            		open: function() {
                        neweditor();
            			//$("#texta").val(temp.html());
            			}
            		});	
                $( "#dialog-form" ).dialog( "open" );
                });

            //xoa div
			$(".imgDelete").click(function(){
            	$(this).parent().parent().remove();
    		});
        	$(".imgDelete").confirm({
        		msg:'Xóa block nhé?',
        		timeout:10000
        	});
            idnum+=1;
		});*/
        //move div
		$( "#main" ).sortable();
		$( "#main" ).disableSelection();
		
		function neweditor(){
			ee = new Editor("ee","abc","descript", "editor2",600,300,'hgh');//e la 1 thuc the, thik tao j cung ok
        	ee.render();//show editor
		}

		 function ggg(){
		    	var tmp=$(this).parent();
		        var temp=$("<div></div>");
		    	var newdiv=$("<div></div>").attr("class","block").attr("id",idname+idnum ).insertAfter(tmp);
		        var newtitle=$("<h3>Block content</h3>");
		        var newcontrol=$("<div class='control'><img src='/Apprentice_CMS/public/images/icon/Delete.png' title='Delete block' class='imgDelete'/></div>");
		        var newclear= $("<div class='clear'></div>");
		        var newcontent=$("<div class='content'>my content</div>");
		        var newpanel=$("<div class='panel' ><img src='/Apprentice_CMS/public/images/icon/New-document.png' class='Newblock' id='"+i+"'/><img src='/Apprentice_CMS/public/images/icon/New-image.png' /> <img src='/Apprentice_CMS/public/images/icon/New-table.png' /> </div>").insertAfter(newdiv);
		        $("#"+i).click(ggg);
		        newtitle.appendTo(newdiv);
		        newcontent.appendTo(newdiv);
		        newcontrol.appendTo(newdiv);
		        newclear.appendTo(newdiv);
		        //newpanel.appendTo(newdiv);
		        i+=1;
		        $(".content").bind("dblclick",function(){
	            	var temp=$(this);
	                $("#dialog-form").dialog({
	            		autoOpen: false,
	            		height: 400,
	            		width: 800,
	            		modal: true,
	            		buttons:{
	            			"Save":function(){
	            				//temp.html($("#texta").val());
	            				$(this).dialog("close");
	            				}
	            			},
	            		open: function() {
	                        neweditor();
	            			//$("#texta").val(temp.html());
	            			}
	            		});	
	                $( "#dialog-form" ).dialog( "open" );
	                });

	            //xoa div
				$(".imgDelete").click(function(){
	            	$(this).parent().parent().remove();
	    		});
	        	$(".imgDelete").confirm({
	        		msg:'Xóa block nhé?',
	        		timeout:10000
	        	});
	            idnum+=1;
		        }	
    });
    </script>

</head>
<body>
	<div id="dialog-form" style="background: white;">
		<span id="edit">loading...</span>
		<!--<textarea id="texta" rows="10" cols="70" style="width: 100%;"></textarea>
	-->
		<script type="text/javascript">
			eee = new Editor("eee","abc","descript", "edit",600,300,'hgh');//e la 1 thuc the, thik tao j cung ok
    		eee.render();//show editor
		</script>
	</div>
    <div id="main">  
    	<h4>Chỉnh sửa bài viết</h4>      
        <div class="block">
            <h3>Title</h3>
            <div id="titles">
                <?php echo $this->newsTitle?>
            </div>
            
            <div class="control">
                <a href="#" title="Edit"><img src="/Apprentice_CMS/public/images/icon/Edit.png" /> </a>
            </div>
            <div class="clear"></div>
        </div>
        
        <div class="block">
            <h3>Description</h3>
            <div id="description">
                <?php echo $this->newsDescription?>
            </div>
            
            <div class="control">
                <a href="#" title="Edit"><img src="/Apprentice_CMS/public/images/icon/Edit.png" /> </a>
            </div>
            <div class="clear"></div>
        </div>
        
        <div class="block">
            <h3>Order news</h3>
            <div id="order">
			
            </div>
            
            <div class="control">
                <a href="#" title="Edit"><img src="/Apprentice_CMS/public/images/icon/Edit.png" /> </a>
            </div>
            <div class="clear"></div>
        </div>
        
        <?php         	
        	$temp=new SimpleXMLElement($this->newsContent);        		
        	foreach ($temp->children() as $t){
        		$i=0;
        		foreach($t->children() as $s){        			
        			if($s["class"]=='img'){
        				$i++;
        				break;
        			}
        		}
        		if($i==0){
        			echo "<div>";
        			$te=new SimpleXMLElement("<div class='panel'>
            		<a class='Newblock' title='New block content'><img src='/Apprentice_CMS/public/images/icon/New-document.png' /> </a>
            		<a href='#' title='New image'><img src='/Apprentice_CMS/public/images/icon/New-image.png' /> </a>
            		<a href='#' title='New table'><img src='/Apprentice_CMS/public/images/icon/New-table.png' /> </a>
        			</div>");
        			echo $te->asXML();
        			
        			$dom=dom_import_simplexml($t);
        			$child=$dom->ownerDocument->createElement("h3","Block Content");
        			
        			$control=$dom->ownerDocument->createElement("div");
        			$control->setAttribute("class", "control");
        			
        			$edit=$control->ownerDocument->createElement("a");
        			$edit->setAttribute("href", "#");
        			$edit->setAttribute("title", "Edit");
        			$imgEdit=$edit->ownerDocument->createElement("img");
        			$imgEdit->setAttribute("src", "/Apprentice_CMS/public/images/icon/Edit.png");
        			$edit->appendChild($imgEdit);
        			$control->appendChild($edit);
        			
        			$moveup=$control->ownerDocument->createElement("a");
        			$moveup->setAttribute("href", "#");
        			$moveup->setAttribute("title", "Move Up");
        			$imgMoveup=$moveup->ownerDocument->createElement("img");
        			$imgMoveup->setAttribute("src", "/Apprentice_CMS/public/images/icon/Up.png");
        			$moveup->appendChild($imgMoveup);
        			$control->appendChild($moveup);
        			
        			$movedown=$control->ownerDocument->createElement("a");
        			$movedown->setAttribute("href", "#");
        			$movedown->setAttribute("title", "Move Down");
        			$imgMovedown=$movedown->ownerDocument->createElement("img");
        			$imgMovedown->setAttribute("src", "/Apprentice_CMS/public/images/icon/Down.png");
        			$movedown->appendChild($imgMovedown);
        			$control->appendChild($movedown);
        			
        			$delete=$control->ownerDocument->createElement("a");
        			//$delete->setAttribute("href", "#");
        			$delete->setAttribute("title", "Delete Block");
        			$imgDelete=$delete->ownerDocument->createElement("img");
        			$delete->setAttribute("class", "imgDelete");
        			$imgDelete->setAttribute("src", "/Apprentice_CMS/public/images/icon/Delete.png");
        			$delete->appendChild($imgDelete);
        			$control->appendChild($delete);
        			
        			$clear=$dom->ownerDocument->createElement("div","");
        			$clear->setAttribute("class", "clear");
        			//$control->appendChild($clear);
        			
        			$dom->insertBefore($child,$dom->firstChild);      			
        			$dom->appendChild($control);
        			$dom->appendChild($clear);       			
        			echo $t->asXML();
        			
        			
        			echo "</div>";
        			
        			
        		}
        		
        		else{
        			$dom=dom_import_simplexml($t);
        			$child=$dom->ownerDocument->createElement("h3","Block Image");
        			$control=$dom->ownerDocument->createElement("div");
        			$control->setAttribute("class", "control");
        			
        			$edit=$control->ownerDocument->createElement("a");
        			$edit->setAttribute("href", "#");
        			$edit->setAttribute("title", "Edit");
        			$imgEdit=$edit->ownerDocument->createElement("img");
        			$imgEdit->setAttribute("src", "/Apprentice_CMS/public/images/icon/Edit.png");
        			$edit->appendChild($imgEdit);
        			$control->appendChild($edit);
        			
        			$moveup=$control->ownerDocument->createElement("a");
        			$moveup->setAttribute("href", "#");
        			$moveup->setAttribute("title", "Move Up");
        			$imgMoveup=$moveup->ownerDocument->createElement("img");
        			$imgMoveup->setAttribute("src", "/Apprentice_CMS/public/images/icon/Up.png");
        			$moveup->appendChild($imgMoveup);
        			$control->appendChild($moveup);
        			
        			$movedown=$control->ownerDocument->createElement("a");
        			$movedown->setAttribute("href", "#");
        			$movedown->setAttribute("title", "Move Down");
        			$imgMovedown=$movedown->ownerDocument->createElement("img");
        			$imgMovedown->setAttribute("src", "/Apprentice_CMS/public/images/icon/Down.png");
        			$movedown->appendChild($imgMovedown);
        			$control->appendChild($movedown);
        			
        			$delete=$control->ownerDocument->createElement("a");
        			//$delete->setAttribute("href", "#");
        			
        			$delete->setAttribute("title", "Delete Block");
        			$imgDelete=$delete->ownerDocument->createElement("img");
        			$delete->setAttribute("class", "imgDelete");
        			$imgDelete->setAttribute("src", "/Apprentice_CMS/public/images/icon/Delete.png");
        			$delete->appendChild($imgDelete);
        			$control->appendChild($delete);
        			
        			$clear=$dom->ownerDocument->createElement("div","");
        			$clear->setAttribute("class", "clear");
        			//$control->appendChild($clear);
        			
        			$dom->insertBefore($child,$dom->firstChild);
        			$dom->appendChild($control);
        			$dom->appendChild($clear);       			
        			echo $t->asXML();
        			
        			$te=new SimpleXMLElement("<div class='panel'>
            		<a class='Newblock' title='New block content'><img src='/Apprentice_CMS/public/images/icon/New-document.png' /> </a>
            		<a href='#' title='New image'><img src='/Apprentice_CMS/public/images/icon/New-image.png' /> </a>
            		<a href='#' title='New table'><img src='/Apprentice_CMS/public/images/icon/New-table.png' /> </a>
        			</div>");
        			echo $te->asXML(); 
        		}
        				
        	}
        ?>

        <div class="block">
            <h3>Author</h3>
            <div id="author">
                <?php echo $this->newsAuthor?>
            </div>
            
            <div class="control">
                <a href="#" title="Edit"><img src="/Apprentice_CMS/public/images/icon/Edit.png" /> </a>
            </div>
            <div class="clear"></div>
        </div>
        <div class="button">
        	<a href="#" title="Save">
        		<img src="/Apprentice_CMS/public/images/icon/Save32.png" />
        	</a>
        </div>	
    </div>
</body>
</html>
